//
//  PYHeaderView.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit

class PYHeaderView: SYBaseView {
    
    var model: PYQModel!
    let pic: UIImageView = {
        let v = UIImageView()
        
        return v
    }()
    
    let headPic: UIImageView = {
        let v = UIImageView()
        v.layer.cornerRadius = 36.0.autoWidth()
        v.isUserInteractionEnabled = true
        v.clipsToBounds = true
        return v
    }()
    
    let smallHeadPic: UIImageView = {
        let v = UIImageView()
        v.clipsToBounds = true
        v.layer.cornerRadius = 10.0.autoWidth()
        return v
    }()
    
    let arrowPic: UIImageView = {
        let v = UIImageView()
        
        
        return v
    }()
    
    let nameLb: UILabel = {
        let v = UILabel()
        
        v.textColor = UIColor.white
        v.font = 15.autoFontSize()
        return v
    }()
    let contentLb: UILabel = {
        let v = UILabel()
        
        v.textColor = UIColor(hex: 0x333333)
        v.font = 12.autoFontSize()
        return v
    }()
    
    var tipBgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = Constant.bgViewColor
        v.layer.cornerRadius = 4
        return v
    }()
    
    var headBgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor.white
        v.layer.cornerRadius = 37.0.autoWidth()
        return v
    }()
    
    let headBt: UIButton = {
        let v: UIButton  = UIButton()
        return v
    }()
    
    let tipBt: UIButton = {
        let v: UIButton  = UIButton()
        return v
    }()
    
    func configure(_ model: PYQModel?) {
        self.model = model
        pic.kf.setImage(with: URL(string: String(format: "%@%@", IMGIP, model?.data?.appUser?.dynamicImg ?? "")))
        headPic.kf.setImage(with: URL(string: String(format: "%@%@", IMGIP, model?.data?.appUser?.headImg ?? "")))
        nameLb.text = model?.data?.appUser?.trueName
        if let _ = model?.data?.shVo {
            contentLb.text = "您的发布未通过审核"
            smallHeadPic.image = UIImage(named: "tanhao")
            contentLb.textColor = UIColor(hex: 0xFFA800)
            tipBgView.backgroundColor = UIColor(hex: 0xFFEBC1)
            arrowPic.image = UIImage(named: "yellow_arrow")
        } else if let dz = model?.data?.dynamicVO {
            contentLb.text = "\(dz.appUser?.trueName ?? "")刚刚赞了您！"
            smallHeadPic.kf.setImage(with: URL(string: String(format: "%@%@", IMGIP, dz.appUser?.headImg ?? "")))
            contentLb.textColor = UIColor(hex: 0x333333)
            tipBgView.backgroundColor = Constant.bgViewColor
            arrowPic.image = UIImage(named: "zan_arrow")
        }
    }
    
    func myListConfigure(_ model: PYMyListModel?) {
        pic.kf.setImage(with: URL(string: String(format: "%@%@", IMGIP, model?.data?.appUser?.dynamicImg ?? "")))
        headPic.kf.setImage(with: URL(string: String(format: "%@%@", IMGIP, model?.data?.appUser?.headImg ?? "")))
        nameLb.text = model?.data?.appUser?.trueName
    }
    
    
    
    override func initViews() {
        
        headBt.addTarget(self, action: #selector(headAction), for: .touchUpInside)
        tipBt.addTarget(self, action: #selector(tipBtAction), for: .touchUpInside)
        self.backgroundColor = .white
        addSubview(pic)
        addSubview(nameLb)
        addSubview(tipBgView)
        addSubview(headBgView)
        tipBgView.addSubview(smallHeadPic)
        tipBgView.addSubview(contentLb)
        tipBgView.addSubview(arrowPic)
        tipBgView.addSubview(tipBt)
        headBgView.addSubview(headPic)
        headBgView.addSubview(headBt)
        pic.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(200.0.autoWidth())
        }
        headBgView.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-14.0.autoWidth())
            make.bottom.equalTo(pic.snp.bottom).offset(26.0.autoWidth())
            make.height.width.equalTo(74.0.autoWidth())
        }
        headPic.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.height.width.equalTo(72.0.autoWidth())
        }
        headBt.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        tipBgView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(pic.snp.bottom).offset(41.0.autoWidth())
            make.height.equalTo(30.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.right.equalTo(pic.snp.right).offset(-95.0.autoWidth())
            make.bottom.equalTo(pic.snp.bottom).offset(-8.0.autoWidth())
            make.height.equalTo(14.0.autoWidth())
        }
        smallHeadPic.snp.makeConstraints { (make) in
            make.centerY.equalTo(tipBgView)
            make.left.equalTo(tipBgView).offset(7.5.autoWidth())
            make.width.height.equalTo(20.0.autoWidth())
        }
        contentLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(tipBgView)
            make.left.equalTo(smallHeadPic.snp.right).offset(5.5.autoWidth())
            make.height.equalTo(12.0.autoWidth())
            make.right.equalTo(arrowPic.snp.left).offset(-7.5.autoWidth())
        }
        arrowPic.snp.makeConstraints { (make) in
            make.centerY.equalTo(tipBgView)
            make.right.equalTo(tipBgView).offset(-7.0.autoWidth())
            make.height.equalTo(7.0.autoWidth())
            make.width.equalTo(4.0.autoWidth())
        }
        tipBt.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
    
    @objc func headAction() {
        let vc = PYMyPyqListViewController()
        self.currentVC.navigationController?.pushViewController(vc, animated: true)
    }
    
    
    @objc func tipBtAction() {
        
        let vc = PYQLoveListViewController()
        self.currentVC.navigationController?.pushViewController(vc, animated: true)
        
    }
}
